package com.qf.fengmimall.index.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.fengmimall.index.entity.Category;
import com.qf.fengmimall.dto.CategoryProductDto;
import com.qf.fengmimall.index.entity.IndexImg;
import com.qf.fengmimall.product.entity.Product;
import com.qf.fengmimall.index.service.ICategoryService;
import com.qf.fengmimall.index.service.IIndexImgService;
import com.qf.fengmimall.product.service.IProductService;
import com.qf.fengmimall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图  前端控制器
 * </p>
 *
 * @author lx
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/index")
@CrossOrigin
public class IndexController {

    @Autowired
    private IIndexImgService indexImgService;

    @Autowired
    private ICategoryService categoryService;
    @Autowired
    private IProductService productService;

    /**
     * 获取轮播图
     *
     * @return
     */
    @RequestMapping("/indeximg")
    public ResultVo getIndexImgs() {
        List<IndexImg> indexImgs = indexImgService.list(new LambdaQueryWrapper<IndexImg>().eq(IndexImg::getStatus, 1).orderByAsc(IndexImg::getSeq));
        return ResultVo.ok(indexImgs);
    }

    /**
     * 获取分级列表
     *
     * @return
     */
    @RequestMapping("/category-list")
    public ResultVo getCategoryList() {
        List<Category> categorys = categoryService.getCategorys();
        return ResultVo.ok(categorys);
    }

    /**
     * 商品推荐
     *
     * @return
     */
    @RequestMapping("/list-recommends")
    public ResultVo getCategoryreCommends() {
        List<Product> products = productService.getCategoryreCommends();
        return ResultVo.ok(products);
    }

    /**
     * 分类商品推荐
     *
     * @return
     */
    @RequestMapping("/category-recommends")
    public ResultVo categoryRecommends() {
        List<CategoryProductDto> categoryProductRecommends = categoryService.getCategoryProduct();
        return ResultVo.ok(categoryProductRecommends);
    }


}
